\documentclass[12pt,a4paper]{article}
\usepackage{xeCJK}
\usepackage{ctex}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage{algorithmicx}
\usepackage[ruled]{algorithm}
\usepackage{algpseudocode}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{color}
\usepackage{bm}
\usepackage{url}
\usepackage{cite}
\usepackage{array}
\usepackage{textcomp}
\usepackage{appendix}
\usepackage{listings}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
  language=Python,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=left,%设置行号位置none不显示行号
  %numberstyle=\tiny\courier, %设置行号大小
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  escapeinside=``,%逃逸字符(1左面的键)，用于显示中文例如在代码中`中文...`
  tabsize=4,
  extendedchars=false %解决代码跨页时，章节标题，页眉等汉字不显示的问题
}



\renewcommand\refname{参考文献}
\setlength{\parindent}{2em}


\setstretch{1.2} 
\setlength{\parindent}{0.8cm}
\geometry{left=3cm,right=3cm,top=2cm,bottom=2cm}
\title{\vspace{-2cm} \textbf{Report of Programming Assignments 1}}
\author{赵竟廷  3200105665}
\date{}

\begin{document}

\maketitle

\section{项目简述}
本次变成项目共包含func.h,EquationSolver.h,main.cpp和Makefile四个子项目。其中前三个项目分别是解决1.8.2中所有编程问题的头文件及主函数，其中每道题所对应的具体函数均存放在主函数中。为便于查看所有题目结果，项目采取了统一输出结果的方式。

本项目通过Makefile对这些子项目进行统一管理，运行时仅需在终端输入make即可编译并获得相应的结果。


\section{程序结果}

本项目采用统一输出的方式，对本次作业中的所有问题结果进行了统一输出如下，即输入make运行可得到如下结果。

\lstset{language=C}

\lstset{
    %numbers=left, 
    %numberstyle= \tiny, 
    keywordstyle= \color{ blue!70},
    commentstyle= \color{red!50!green!50!blue!50}, 
    frame=shadowbox, % 阴影效果
    rulesepcolor= \color{ red!20!green!20!blue!20} ,
    escapeinside=``, % 英文分号中可写入中文
    xleftmargin=2em, aboveskip=1em,
    framexleftmargin=2em
}

\begin{lstlisting}
----- problem B ----- 
Answer of problem B_1 is 0.860334 f(x*)= 0
Answer of problem B_2 is 0.641186 f(x*)= 0
Answer of problem B_3 is 1.82938 f(x*)= 0
Answer of problem B_4 is 0.117877 f(x*)= -1.21841e+16
----- problem C ----- 
Answer of problem C is 4.49341 and 7.72525
f(x1*)= -8.88178e-16 and f(x2*)= 2.30926e-14
----- problem D ----- 
Answer of problem D_1 is 3.14159 f(x*)= -1.11022e-16
Answer of problem D_2 is 1.30633 f(x*)= -4.44089e-16
Answer of problem D_3 is -0.188685 f(x*)= 0
Answer of problem D_1 with initial values 0 and pi is 3.14159 f(x*)= 0
Answer of problem D_2 with initial values 1 and 2 is 0.917826 f(x*)= 1.19648
Answer of problem D_3 with initial values 0 and 3 is -0.188685 f(x*)= 0
----- problem E ----- 
Answer of problem E by Bisection method is 0.835938 f(x*)= 0.0192627
Answer of problem E by Newton method is 0.834981 f(x*)= -1.77636e-15
Answer of problem E by Secant method is 0.834981 f(x*)= 4.31406e-06
----- problem F ----- 
Answer of problem F_a is 32.9722 degrees f(x*)= 0
Answer of problem F_b is 33.1689 degrees f(x*)= 0
Answer of problem F_a by Secant method is -212.972 degrees f(x*)= 0

\end{lstlisting}


\section{结果及分析}
对于仅要求给出具体计算结果的问题，上文中已经有了明确的展示，且其求解均较为准确，在此不做赘述，仅作简要展示。而对于需要分析的题目，本部分将继续给出一定的分析内容。
需要说明的是，对各个方法的准确性验证，是通过将解带回原方程计算函数值与0的接近程度来考察的。结果中$x*$表示算法所求得的解。
\subsection{Problem A}
根据A中的要求，建立了相应的头文件EquationSolver.h来储存三种求解方法：Bisection,Newton's method,Secant method。
\subsection{Problem B}
\begin{lstlisting}
Answer of problem B_1 is 0.860334 f(x*)= 0
Answer of problem B_2 is 0.641186 f(x*)= 0
Answer of problem B_3 is 1.82938 f(x*)= 0
Answer of problem B_4 is 0.117877 f(x*)= -1.21841e+16
\end{lstlisting}

不难看出，最后一题使用二分法计算出的结果具有较大误差，其并非方程的根。造成该现象的原因可能是由于当带入所求得的解时，函数的分母部分与0十分接近，而导致计算机在进行计算的过程中出现误差，同时也可能是给定的函数在该区间内不连续，从而使二分法无法正常使用，基于前一个原因不难想到，可能在接近计算解的位置存在函数不连续的情况。
\subsection{Problem C}
C题的结果如下。
\begin{lstlisting}
Answer of problem C is 4.49341 and 7.72525
f(x1*)= -8.88178e-16 and f(x2*)= 2.30926e-14
\end{lstlisting}
两个解分别代回原函数所求得的结果均与0非常接近，可以看出牛顿法的求解是较为精准的。
\subsection{Problem D}
依据题干要求，更换不同的初始值得到的结果如下
\begin{lstlisting}
Answer of problem D_1 is 3.14159 f(x*)= -1.11022e-16
Answer of problem D_2 is 1.30633 f(x*)= -4.44089e-16
Answer of problem D_3 is -0.188685 f(x*)= 0
Answer of problem D_1 with initial values 0 and pi is 3.14159 f(x*)= 0
Answer of problem D_2 with initial values 1 and 2 is 0.917826 f(x*)= 1.19648
Answer of problem D_3 with initial values 0 and 3 is -0.188685 f(x*)= 0

\end{lstlisting}

可以看出，当初始值发生变化时，其解可能会出现不同的情况。根据书中定理及割线法的具体描述可知，割线法的前提条件是需要初值尽可能接近于真实解，因此，当更换初值时可能会由于该初值不足够接近于要求的真实解或者有其他更接近的解而使结果不够准确或不同。

\subsection{Problem E}
依据题干要求，认为0.01ft是题目所允许的误差范围，因此设置bisection method和secant method的$\delta$值均为0.01。
所得到的结果为
\begin{lstlisting}
Answer of problem E by Bisection method is 0.835938 f(x*)= 0.0192627
Answer of problem E by Newton method is 0.834981 f(x*)= -1.77636e-15
Answer of problem E by Secant method is 0.834981 f(x*)= 4.31406e-06
\end{lstlisting}
若理解为结果最后保留的小数位数精确到0.01ft而程序中的精度正常取到更小的值，则所得结果为

\begin{lstlisting}
Answer of problem E by Bisection method is 0.83
Answer of problem E by Newton method is 0.83
Answer of problem E by Secant method is 0.83

\end{lstlisting}

\subsection{Problem F}
\begin{lstlisting}
Answer of problem F_a is 32.9722 degrees f(x*)= 0
Answer of problem F_b is 33.1689 degrees f(x*)= 0
Answer of problem F_a by Secant method is -212.972 degrees f(x*)= 0
\end{lstlisting}

第三小问，沿用第一小问的数据后选取与33度相差较远的两个初值0和90度，则计算出的结果与第一小问不同，但是其代回原函数所求得的结果是0。其原因可能同样是因为初值距离真实解较远，从而导致计算出了另一个距离较远的解（该函数的解并不唯一）。但根据题意可知，$\alpha$不可能为负值，因此该结果依然不可取（或称为不合理的解）。推理可知，继续改变不同的初值，则可能获得准确度较低的合理解，或是准确度较高的不合理解，而当初值接近33度时，则可以较好地求得精确度较高的合理解。

\end{document}